package com.indexingsystem.db.mongoDB.comon;

/**
 * MongoDB数据库字段与java字段对照
 */
public enum FieldMapping {

	ID("_id", "_id", "mongo objectid"), CREATE_TIME("create_time", "createTime", "生成时间")

	, PROCESS_TYPE("process_type", "processType", "流程类型");

	private String	mongoField;
	private String	javaField;
	private String	description;

	private FieldMapping(String mongoField, String javaField, String description) {
		this.mongoField = mongoField;
		this.javaField = javaField;
		this.description = description;
	}

	/**
	 * @return the mongoField
	 */
	public String getMongoField() {
		return mongoField;
	}

	/**
	 * @param mongoField
	 *            the mongoField to set
	 */
	public void setMongoField(String mongoField) {
		this.mongoField = mongoField;
	}

	/**
	 * @return the javaField
	 */
	public String getJavaField() {
		return javaField;
	}

	/**
	 * @param javaField
	 *            the javaField to set
	 */
	public void setJavaField(String javaField) {
		this.javaField = javaField;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * 根据mongoDB字段获取枚举
	 * 
	 * @Title: getFieldMappingByMongoDBField
	 * @see:
	 * @param mongoDBField
	 * @return
	 * @return FieldMapping 返回类型
	 * @throws
	 */
	public static FieldMapping getFieldMappingByMongoDBField(String mongoDBField) {
		if (mongoDBField == null)
			return null;
		FieldMapping[] es = FieldMapping.values();
		for (FieldMapping fieldMapping : es) {
			if (fieldMapping.getMongoField().equals( mongoDBField ))
				return fieldMapping;
		}
		return null;
	}

	/**
	 * 根据java字段获取枚举
	 * 
	 * @Title: getFieldMappingByJavaField
	 * @see: TODO
	 * @param javaField
	 * @return
	 * @return FieldMapping 返回类型
	 * @throws
	 */
	public static FieldMapping getFieldMappingByJavaField(String javaField) {
		if (javaField == null)
			return null;
		FieldMapping[] es = FieldMapping.values();
		for (FieldMapping fieldMapping : es) {
			if (fieldMapping.getJavaField().equals( javaField ))
				return fieldMapping;
		}
		return null;
	}

}
